/*
 * ADCQueueManager.h
 *
 *  Created on: May 11, 2010
 *      Author: Mario Rodriguez Huizar
 */

#ifndef ADCQUEUEMANAGER_H_
#define ADCQUEUEMANAGER_H_

#include "ADCQueue.h"
#include <assert.h>

class ADCQueueManager{
private:
	ADCQueue *myADCQueues;
	uint16_t totalADCpackets;
	uint16_t maxQueueSize;  //maximum Size it is allowed a queue to grow
	uint8_t maxChannels;    //maximum number of Channels/Queues
public:
	ADCQueueManager(uint16_t theMaxQueueSize, uint8_t theMaxChannels){
		totalADCpackets=0;
		maxQueueSize=theMaxQueueSize;
		maxChannels = theMaxChannels;
		myADCQueues = new ADCQueue[maxChannels];
	}

	bool pushADCpacket(uint8_t channel, ADCPacket *adcData){
		assert(adcData);
		assert(channel<maxChannels);
		if(myADCQueues[channel].GetLength()<maxQueueSize){
			myADCQueues[channel].Add(adcData);
			totalADCpackets++;
			return true;
		}else{ //the queue is full
			myADCQueues[channel].Remove(); //so drop the oldest packet info is lost
			myADCQueues[channel].Add(adcData);//insert the new packet
			return false;
		}
	}

	ADCPacket *popADCpacket(uint8_t channel){
		ADCPacket *popedData;
		assert(myADCQueues[channel].GetLength()>0);
		popedData = myADCQueues[channel].Remove();
		assert(popedData);
		totalADCpackets--;
		return popedData;
	}

	uint8_t getTotalLength(){
		return totalADCpackets;
	}

	~ADCQueueManager(){
		delete [] myADCQueues;
	}
};


#endif /* ADCQUEUEMANAGER_H_ */
